package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.SightOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 景点门票预定数据操作持久层接口
 * @Author HZX
 * @Version 1.0
 * @Date 2020/6/26 11:30
 */
@Repository
public interface ISightOrderDao {

    /**
     * @Description 添加景点门票订单
     *
     * @param sightOrder
     * @return boolean
     */
    @Insert("insert into tb_sight_order(orderId, userId, detailTypeId, tripDate, realName, IDCard, phone, " +
            "orderNum, orderStatus, payAmount, payType, createTime, tradeNo) " +
            "values(#{sightOrder.orderId},#{sightOrder.userId},#{sightOrder.detailTypeId},#{sightOrder.tripDate},#{sightOrder.realName},#{sightOrder.IDCard},#{sightOrder.phone}," +
            "#{sightOrder.orderNum},#{sightOrder.orderStatus},#{sightOrder.payAmount},#{sightOrder.payType},#{sightOrder.createTime},#{sightOrder.tradeNo})")
    int insert(@Param("sightOrder") SightOrder sightOrder) throws SQLException;

    /**
     * @Description 通过订单id删除景点门票订单
     *
     * @param orderId
     * @return int
     */
    @Delete("delete from tb_sight_order where orderId=#{orderId}")
    int delete(String orderId) throws SQLException;

    /**
     * @Description 通过订单id查找景点门票订单
     *
     * @param orderId
     * @return cn.hut.travel.bean.SightOrder
     */
    @Select("select * from tb_sight_order where orderId=#{orderId}")
    SightOrder selectByOrderId(String orderId) throws SQLException;

    /**
     * @Description 通过用户id查找该用户所有的景点门票订单
     *
     * @param userId
     * @return java.util.List<cn.hut.travel.bean.SightOrder>
     */
    @Select("select * from tb_sight_order where userId=#{userId}")
    List<SightOrder> selectByUserId(String userId) throws SQLException;

    /**
     * @Description 通过订单号修改订单状态
     *
     * @param orderId
     * @param orderStatus
     * @return int
     */
    @Update("update tb_sight_order set orderStatus=#{orderStatus} where orderId=#{orderId}")
    int updateOrderStatus(@Param("orderId") String orderId, @Param("orderStatus") Integer orderStatus) throws SQLException;

    /**
     * @Description 通过订单id添加订单交易号
     *
     * @param out_trade_no
     * @param trade_no
     * @return int
     */
    @Insert("update tb_sight_order set tradeNo=#{trade_no} where orderId=#{out_trade_no}")
    int addTradeNoByOrderId(@Param("out_trade_no") String out_trade_no, @Param("trade_no") String trade_no) throws SQLException;

    /**
     * @Description 查询所有的景点订单
     *
     * @param
     * @return java.util.List<cn.hut.travel.bean.SightOrder>
     */
    @Select("select * from tb_sight_order")
    List<SightOrder> selectAll() throws SQLException;

    /**
     * @Description 通过用户id和订单状态查询该用户待付款的景点订单
     *
     * @param userId
     * @param orderStatus
     * @return java.util.List<cn.hut.travel.bean.SightOrder>
     */
    @Select("select * from tb_sight_order where userId=#{userId} and orderStatus=#{orderStatus}")
    List<SightOrder> selectByUserIdAndStatus(@Param("userId") String userId, @Param("orderStatus") Integer orderStatus) throws SQLException;

}
